package com.xyy.saas.payment.cores.enums;

import java.util.Arrays;
import java.util.Map;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

/**
 * 京东支付 交易状态
 */
public enum JDPayTradeStatusEnum {

    ACSU("ACSU", "受理成功"),
    BUID("BUID", "交易建立"),
    WPAR("WPAR", "等待支付结果"),
    CLOS("CLOS", "交易关闭，交易失败"),
    FINI("FINI", "成功"),
    REFU("REFU", "退款");

    /**
     * 验证是否为有效状态
     */
    public static boolean effectiveStatus(String tradeStatus) {
        return JDPayTradeStatusEnum.CLOS.getCode().equals(tradeStatus) || JDPayTradeStatusEnum.FINI.getCode().equals(tradeStatus) || JDPayTradeStatusEnum.REFU.getCode().equals(tradeStatus);
    }

    private String code;
    private String desc;

    private static Map<String,JDPayTradeStatusEnum> code2Enum;

    static {
        code2Enum = Arrays.asList(values()).stream().collect(Collectors.toMap(JDPayTradeStatusEnum::getCode, UnaryOperator.identity()));
    }

    JDPayTradeStatusEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static JDPayTradeStatusEnum getEnum(String code){
        return code2Enum.get(code);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

}
